import { IClassifyList } from "../api/type";

export class PreviewListModel {
    private static instance: PreviewListModel;

    private constructor() {
        // 私有构造函数，防止外部通过 new 关键字创建实例
        console.log("创建单例实例");
    }

    public static getInstance(): PreviewListModel {
        if (!PreviewListModel.instance) {
            PreviewListModel.instance = new PreviewListModel();
        }
        return PreviewListModel.instance;
    }
	private previewList:IClassifyList[] = []
	get previewListPicUrlItems(){
		return this.previewList.map(item=>{
			return{
				...item,
				picUrl:item.smallPicurl.replace('_small.webp','.jpg')
			}
		})
	}

	public setPreviewList(list:IClassifyList[]){
		this.previewList = list;
	}
	
	getPreviewList():IClassifyList[]{
		return this.previewList;
	}
	setPreviewAttr(index:number,attr:keyof IClassifyList,value){
		this.previewList[index][attr] = value;
	}
	
	clearPreviewList(){
		this.previewList = [];
	}
}

